<?php
  include_once dirname(__FILE__)."/../../database/database.class.php";
  include_once dirname(__FILE__)."/../../classes/collection.class.php";

  if((isset($_GET['new_collection']) || isset($_GET['remove_collection'])) && isset($_COOKIE["MGTDatabase_user"]) && is_numeric($_COOKIE["MGTDatabase_user"]))
  {
    if(isset($_GET['new_collection']))
    {
      $result = $db->addCollection($_GET['new_collection'], $_COOKIE["MGTDatabase_user"]);
      if(is_string($result))
      {
        echo '<p>'.$result.'</p>';
      }
    }
    if(isset($_GET['remove_collection']) && is_numeric($_GET['remove_collection']))
    {
      $db->removeCollection($_GET['remove_collection']);
    }
  }

if(isset($_COOKIE["MGTDatabase_user"]) && is_numeric($_COOKIE["MGTDatabase_user"]))
{
  $even = FALSE;

  echo '
  <center>
  <table class="collections_overview" cellspacing="0px">
    <tr>
      <th>Collection name</th>
      <th>Unique</th>
      <th>Total</th>
      <th></th>
    </tr>
  ';

  foreach($db->getCollections($_COOKIE["MGTDatabase_user"]) as $collection)
  {
    $collection = new Collection($collection->ID);

    echo '<tr class="'.(($even = !$even) ? "even_row" : "uneven_row").'">
      <td class="collections_name"><a href="?collectionId='.$collection->getID().'">'.$collection->getName().'</a></td>
      <td class="collections_size">'.$collection->getUniqueSize().'</td>
      <td class="collections_size">'.$collection->getSize().'</td>
      <td><a href="?remove_collection='.$collection->getID().'">X</a></td>
    </tr>';

    unset($collection);
  }
  echo'
  </table>
  </center>

  <form>
    <input type="text" name="new_collection"><input type="submit">
  </form>
  ';
}

?>